package api

import (
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
	"videos/api-getaway/basic/config"
	__ "videos/api-getaway/basic/proto"
	"videos/api-getaway/handler/request"
)

func Register(r *gin.Context) {
	var req request.Register
	err := r.ShouldBind(&req)
	if err != nil {
		r.JSON(http.StatusBadRequest, gin.H{
			"code":    400,
			"message": err.Error(),
		})
		return
	}

	r, err = config.UserClient.Register(r, &__.RegisterReq{
		Username: req.Username,
		Password: req.Password,
	})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}

	r.JSON(http.StatusOK, gin.H{})
}
